package com.efast.dmom.aps.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.aps.bean.PlanOrderPartAnalysisResult;
import com.efast.dmom.aps.bean.PlanOrderPartAnalysisResultItem;
import com.efast.dmom.aps.datahandlers.PlanOrderPartAnalysisResultDataHandler;
import com.efast.dmom.aps.datahandlers.PlanOrderPartAnalysisResultItemDataHandler;
import com.efast.dmom.aps.service.PlanOrderPartAnalysisResultService;

@Service
public class PlanOrderPartAnalysisResultServiceImpl implements PlanOrderPartAnalysisResultService {

	@Autowired
	private PlanOrderPartAnalysisResultDataHandler planOrderPartAnalysisResultDataHandler;

	@Autowired
	private PlanOrderPartAnalysisResultItemDataHandler PlanOrderPartAnalysisResultItemDataHandler;

	@Override
	public void save(List<PlanOrderPartAnalysisResult> analysisResultList) {
		if (analysisResultList != null && analysisResultList.size() > 0) {
			planOrderPartAnalysisResultDataHandler.saveList(analysisResultList);
			for (PlanOrderPartAnalysisResult data : analysisResultList) {
				if (data.getResultItemList() != null && data.getResultItemList().size() >= 0) {
					for (PlanOrderPartAnalysisResultItem itemData : data.getResultItemList()) {
						itemData.getInnerData().setAnalysisResultId(data.getInnerData().getId());
					}
					PlanOrderPartAnalysisResultItemDataHandler.saveList(data.getResultItemList());
				}
			}
		}
	}

	@Override
	public void deleteAll() {
		planOrderPartAnalysisResultDataHandler.deleteAll();
		PlanOrderPartAnalysisResultItemDataHandler.deleteAll();
	}

}
